package com.ht.file.action;

import org.apache.struts2.ServletActionContext;

import com.ht.file.entity.CompleUpdateModel;
import com.ht.file.service.CompleUpdateService;
import com.ht.right.service.CommonFacadeService;
import com.ht.right.util.CommonUtil;
import com.ht.right.util.FileCommonUtil;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class CompleUpdateAction extends ActionSupport  implements ModelDriven<CompleUpdateModel>{
	private static final long serialVersionUID = 7815600244972772163L;
	private CompleUpdateService compleUpdateService;
	private CompleUpdateModel compleUpdateModel;
	private CommonFacadeService<CompleUpdateModel> commonFacadeService;

	
	public String findCompleUpdateById(){
		compleUpdateModel = commonFacadeService.getEntityByID("CompleUpdateModel", ServletActionContext.getRequest().getParameter("uuid"));
		CommonUtil.toJsonStr(ServletActionContext.getResponse(), compleUpdateModel);
		return null;
	}
	
	public String findDowloadCompleUpdateById(){
		compleUpdateModel = commonFacadeService.getEntityByID("CompleUpdateModel", ServletActionContext.getRequest().getParameter("uuid"));
		String path = compleUpdateModel.getProfilepath();
		String fileName = compleUpdateModel.getProfilename();
		FileCommonUtil.dowloadFile(fileName, path, ServletActionContext.getResponse());
		return null;
	}
	
	public CompleUpdateService getCompleUpdateService() {
		return compleUpdateService;
	}
	public void setCompleUpdateService(CompleUpdateService compleUpdateService) {
		this.compleUpdateService = compleUpdateService;
	}

	public CompleUpdateModel getCompleUpdateModel() {
		return compleUpdateModel;
	}

	public void setCompleUpdateModel(CompleUpdateModel compleUpdateModel) {
		this.compleUpdateModel = compleUpdateModel;
	}

	@Override
	public CompleUpdateModel getModel() {
		if(CommonUtil.isNullOrEmpty(compleUpdateModel)){
			compleUpdateModel = new CompleUpdateModel();
		}
		return compleUpdateModel;
	}

	public CommonFacadeService<CompleUpdateModel> getCommonFacadeService() {
		return commonFacadeService;
	}

	public void setCommonFacadeService(CommonFacadeService<CompleUpdateModel> commonFacadeService) {
		this.commonFacadeService = commonFacadeService;
	}
	
}
